/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author danilo
 */
@FacesConverter(value="convertMask")
public class ConverterMaskPreco implements Converter{

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        String str=value.replace("R$ ", "");
        str=str.replace(",", ".");
        return Double.parseDouble(str);     
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        String str=value.toString();
        str="R$ "+str;
        str.replace(".", ",");
        return str;
    }
  
    
    public static double convertMask(String value){
         String str=value.replace("R$ ", "");
        str=str.replace(",", ".");
        return Double.parseDouble(str); 
    }
    
}
